﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections.Specialized;

namespace EuphoricNation.Rewrite
{
    /// <summary>
    /// Class for wrapping information about the current rewritten request
    /// Based on: http://www.simple-talk.com/dotnet/asp.net/a-complete-url-rewriting-solution-for-asp.net-2.0/
    /// </summary>
    public class RewriteContext
    {
        public NameValueCollection Params { get; set; }
        public string InitialUrl { get; set; }

        /// <summary>
        /// RewriteContext instance for the current request
        /// </summary>
        public static RewriteContext Current
        {
            get
            {
                // Look for RewriteContext instance in
                // current HttpContext. If there is no RewriteContextInfo
                // item then this means that rewrite module is turned off
                if (HttpContext.Current.Items.Contains("RewriteContextInfo"))
                    return (RewriteContext)HttpContext.Current.Items["RewriteContextInfo"];
                else
                    return new RewriteContext();
            }
        }

        public RewriteContext()
        {
            Params = new NameValueCollection();
            InitialUrl = String.Empty;
        }

        public RewriteContext(NameValueCollection param, string url)
        {
            InitialUrl = url;
            Params = new NameValueCollection(param);
        }
    }
}